package com.android.demo;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.EditText;
import android.widget.RemoteViews.ActionException;
import android.widget.Toast;

public class TestLoading extends Activity implements OnClickListener{
	EditText et;
	/** Called when the activity is first created. */
	AlarmReceiver mAlarmReceiver = new AlarmReceiver();
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.loading);
		
		et = (EditText)findViewById(R.id.edit_text);
		findViewById(R.id.add_btn).setOnClickListener(this);
		findViewById(R.id.insert_btn).setOnClickListener(this);
		
		
		IntentFilter filter = new IntentFilter();
		filter.addAction("com.htc.intent.action.alarm_timeout");
		this.registerReceiver(mAlarmReceiver, filter );
		filter = new IntentFilter();
		filter.addAction("com.htc.intent.lockscreen.StopAlarmRinging");
		this.registerReceiver(mAlarmReceiver, filter );
		filter = new IntentFilter();
		filter.addAction("com.htc.intent.lockscreen.StartAlarmRinging");
		this.registerReceiver(mAlarmReceiver, filter );
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.add_btn:
			et.append("o_______o");
			break;
		case R.id.insert_btn:
			String str = "|-|";
			et.getText().insert(et.getSelectionStart(), str);
			break;
		}
	}
	
	

	@Override
	protected void onDestroy() {
		this.unregisterReceiver(mAlarmReceiver);
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}



	public class AlarmReceiver extends BroadcastReceiver {
	    @Override
	     public void onReceive(Context context, Intent intent) {
	    	Toast.makeText(TestLoading.this, "AlarmReceiver"+intent.getAction(),0).show();
//	    	Toast.makeText(this,"",0)
	   }
	}
	
}
